package comparator;

import java.util.Date;
import java.util.Comparator;
import dataBase.Order;

public class SortByPriority {

	private Long[] urgencyTime;
	
	public void setUrgencyTime(Long[] urgencyTime) {
		this.urgencyTime = urgencyTime;
	}

	public Comparator<Order> getCom() {
		return com;
	}
	private Comparator<Order> com;
	
	public SortByPriority() {
		com = new Comparator<Order>() {
			@Override
			public int compare(Order o1, Order o2) {
				Date firstDate = o1.getDelayDate(urgencyTime); 
				Date secondDate = o2.getDelayDate(urgencyTime);
				if(firstDate==null && secondDate==null)
					return 0;
				if(firstDate==null)
					return 1;
				if(secondDate==null)
					return -1;
				if (firstDate.before(secondDate))
					return -1;
				if (firstDate.after(secondDate))
					return 1;
				return 0;
			}
		};//end of comparator
	}

}
